//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package servlet.register;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import net.sf.json.JSONObject;
import utils.JDBCUtils;

@WebServlet({"/DoDelRegister"})
public class DoDelRegister extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public DoDelRegister() {
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/json; charset=utf-8");
        String id = request.getParameter("id");
        PrintWriter out = response.getWriter();
        HttpSession session = request.getSession();
        if (session.getAttribute("username") != null && !session.getAttribute("username").toString().equals("")) {
            Connection connection = null;
            Statement statement = null;
            ResultSet resultSet = null;

            try {
                connection = JDBCUtils.getConnection();
                statement = connection.createStatement();
                String sql = "delete from in_or_out where id=" + id;
                int result = statement.executeUpdate(sql);
                JSONObject jsonmain = new JSONObject();
                jsonmain.put("code", "200");
                if (result != 0) {
                    jsonmain.put("msg", "deleted");
                    response.setStatus(200);
                } else {
                    jsonmain.put("msg", "Error");
                    response.setStatus(500);
                }

                out.println(jsonmain);
            } catch (ClassNotFoundException var16) {
                ClassNotFoundException e = var16;
                e.printStackTrace();
            } catch (SQLException var17) {
                SQLException e = var17;
                e.printStackTrace();
            } finally {
                JDBCUtils.release((ResultSet)resultSet, statement, connection);
            }

        } else {
            response.setStatus(403);
            out.println("403 Forbidden");
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
